package com.example.utils;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

import androidx.annotation.NonNull;

public class LooperThread extends Thread{
    @Override
    public void run() {
        super.run();
        Looper.prepare();//初始化Looper对象
        Handler handler = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                Log.i("looper", String.valueOf(msg.what));
            }
        };
        Message message = handler.obtainMessage();//获取message
        message.what = 1;
        handler.sendMessage(message);//发送消息
        Looper.loop();//启动looper
    }
}
